package com.luther.design.singleton;

import java.io.ObjectStreamException;

/**
 * 懒汉式（线程不安全）
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> luzhenbang
 * <h3>Date</h3> 03/04/2018 12:51
 * <h3>Copyright</h3> Copyright (c)2018 Shenzhen TL  Co., Ltd. Inc. All rights reserved.
 */
public class SingletonLazy {
    
    private static SingletonLazy singleton  = null ;

    /**
     * 构造方法私有化
     * */
    private  SingletonLazy(){

    }
    public static SingletonLazy getInstance() {
        if (null == singleton){
            singleton = new SingletonLazy();
        }
        return singleton;
    }
    /**
     * 杜绝单例对象被反序列化时重新生成对象
     * @return
     * @throws ObjectStreamException
     */
    private Object readResolve() throws ObjectStreamException {
        return singleton;
    }
}
